package com.cskaoyan.controller.category;

import com.cskaoyan.bean.MallCategory;
import com.cskaoyan.model.bo.category.CategoryDeleteBo;
import com.cskaoyan.model.bo.category.CategoryUpdateBo;
import com.cskaoyan.model.vo.BaseData;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.service.category.CategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: mjm
 * @Date: 2021/11/30
 * @Time: 9:02
 * @Description:
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;


    /**
     * @description: 获取商品类目
     * @param: 无参
     * @return:
     */
    @RequiresPermissions("admin:category:list")
    @GetMapping("list")
    public BaseRespVo categoryList() {
        BaseData baseData = categoryService.categoryList();
        return BaseRespVo.ok(baseData);
    }


    @RequiresPermissions("admin:category:create")
    @PostMapping("create")
    public BaseRespVo categoryCreate(@RequestBody MallCategory mallCategoryBo) {
        MallCategory mallCategoryVo = categoryService.categoryCreate(mallCategoryBo);
        return BaseRespVo.ok(mallCategoryVo);
    }

    @RequiresPermissions("admin:category:update")
    @PostMapping("update")
    public BaseRespVo categoryUpdate(@RequestBody CategoryUpdateBo categoryUpdateBo) {
        int affectedRows = categoryService.categoryUpdate(categoryUpdateBo);
        if (affectedRows == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }


    @RequiresPermissions("admin:category:delete")
    @PostMapping("delete")
    public BaseRespVo categoryDelete(@RequestBody CategoryDeleteBo categoryDeleteBo) {

        int affectedRows = categoryService.categoryDelete(categoryDeleteBo);
        if (affectedRows == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }


    /**
     * @description: 不知名功能
     * @param: 无参
     * @return:
     */
    @GetMapping("l1")
    public BaseRespVo categoryl1() {
        BaseData baseData = categoryService.categoryl1();
        return BaseRespVo.ok(baseData);
    }
}
